home *** CD-ROM | disk | FTP | other *** search
- /* YBookmarks extension ID. */
- const YBOOKMARKS_ID = "{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}";
- /* IDs of extensions that are incompatible with YBookmarks. */
- const Y_BLOCK_LIST =
- ["{5a2b4e34-ce62-42e9-a658-06ba4490adf8}"]; //classic del.icio.us
- const Y_ID_PREFIX = "urn:mozilla:item:";
- /* property used to flag disabled extensions. */
- const Y_DISABLED_PROPERTY = "http://www.mozilla.org/2004/em-rdf#userDisabled";
-
- /**
- * Handles showing a list of all incompatible extensions to the user, and
- * disabling all of them, or alternatively disabling YBookmarks. This is meant
- * to prevent problems such as having more than one extension writing to the
- * bookmarks datasource.
- */
- var yDisableExtensions = {
- /* list of incompatible extensions. */
- _blockList : null,
-
- /**
- * Look for extensions that are known to be incompatible with YBookmarks. If
- * any are found, show a dialog to prompt the user for action.
- * @return an object with one attribute: foundList, holding the array of
- * found incompatible extensions
- */
- getIncompatibleExtensions: function() {
- var result = new Object();
- var em =
- Components.classes["@mozilla.org/extensions/manager;1"].
- getService(Components.interfaces.nsIExtensionManager);
- var extensionList =
- em.getItemList(Components.interfaces.nsIUpdateItem.TYPE_EXTENSION, {});
- var foundList = new Array();
- var extId;
-
- yDebug.print("Looking for incompatible extensions.", YB_LOG_MESSAGE);
-
- for (var i = 0; i < extensionList.length; i++) {
- extId = extensionList[i].id;
-
- for (var j = 0; j < Y_BLOCK_LIST.length; j++) {
- if (Y_BLOCK_LIST[j] == extId) {
- if (this._isEnabled(extId, em)) {
- foundList.push(extensionList[i]);
- }
-
- break;
- }
- }
- }
-
- yDebug.print(
- "Found " + foundList.length + " incompatible extensions.",
- YB_LOG_MESSAGE);
-
- result.foundList = foundList;
- return result;
- },
-
- /**
- * Determine if an extension is enabled.
- * @param extensionId the ID of the extension.
- * @param em the extension manager component.
- * @return true if the extension is enabled. false otherwise.
- */
- _isEnabled: function(extensionId, em) {
- var result = true;
- var rs =
- Components.classes["@mozilla.org/rdf/rdf-service;1"].
- getService(Components.interfaces.nsIRDFService);
- var extensionDS = em.datasource;
- var resourceId = rs.GetResource(Y_ID_PREFIX + extensionId);
- var propertyDisabled = rs.GetResource(Y_DISABLED_PROPERTY);
- var resourceDisabled =
- extensionDS.GetTarget(resourceId, propertyDisabled, true);
-
- /* if the property is not set, the extension is enabled. */
- if (resourceDisabled) {
- resourceDisabled.QueryInterface(Components.interfaces.nsIRDFLiteral);
- result = (resourceDisabled.Value != "true");
- }
-
- return result;
- },
-
- /**
- * Initializes the dialog by filling the incompatible extension list.
- * @return returns true for success.
- */
- init : function() {
- var extensionList = document.getElementById("extension-list");
- var insertedItem;
-
- this._blockList = window.arguments[0];
-
- for (var i = 0; i < this._blockList.length; i++) {
- insertedItem = extensionList.appendItem(
- this._blockList[i].name, this._blockList[i].id);
- insertedItem.setAttribute("class", "listitem-iconic");
- insertedItem.setAttribute("image", this._blockList[i].iconURL);
- }
-
- return true;
- },
-
- /**
- * Disables all incompatible extensions and prompts the user to restart.
- * @return returns true for success.
- */
- disableExtensions : function() {
- yDebug.print("Disabling incompatible extensions.", YB_LOG_MESSAGE);
- var em =
- Components.classes["@mozilla.org/extensions/manager;1"].
- getService(Components.interfaces.nsIExtensionManager);
- var os =
- Components.classes["@mozilla.org/observer-service;1"].
- getService(Components.interfaces.nsIObserverService);
-
- for (var i = 0; i < this._blockList.length; i++) {
- em.disableItem(this._blockList[i].id);
- }
-
- os.notifyObservers(null, "ybookmark.disableExtension", "accept");
-
- return true;
- },
-
- /**
- * Cancels the incompatible extension dialog. It notifies an observer to
- * disable this extension.
- * @return returns true for success.
- */
- cancelDialog : function() {
- var os = Components.classes["@mozilla.org/observer-service;1"].
- getService(Components.interfaces.nsIObserverService);
- os.notifyObservers(null, "ybookmark.disableExtension", "cancel");
-
- return true;
- },
-
- /**
- * Disables the Ybookmarks extension and prompts the user to restart.
- * @return returns true for success.
- */
- disableYBookmarks : function() {
- var em =
- Components.classes["@mozilla.org/extensions/manager;1"].
- getService(Components.interfaces.nsIExtensionManager);
-
- em.disableItem(YBOOKMARKS_ID);
- },
-
- /**
- * Uninstalls the Ybookmarks extension
- */
- uninstallYBookmarks : function() {
- var em =
- Components.classes["@mozilla.org/extensions/manager;1"].
- getService(Components.interfaces.nsIExtensionManager);
-
- em.uninstallItem(YBOOKMARKS_ID);
- },
-
- };
-
-